package com.manage.modules.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.manage.common.annotation.Log;
import com.manage.common.core.controller.BaseController;
import com.manage.common.core.domain.AjaxResult;
import com.manage.common.enums.BusinessType;
import com.manage.modules.vo.TBaseEquipTypeVo;
import com.manage.modules.bo.TBaseEquipTypeQueryBo;
import com.manage.modules.bo.TBaseEquipTypeAddBo;
import com.manage.modules.bo.TBaseEquipTypeEditBo;
import com.manage.modules.service.ITBaseEquipTypeService;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 设备类型Controller
 *
 * @author wx
 * @date 2021-08-12
 */
@Api(value = "设备类型控制器", tags = {"设备类型管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/modules/equipType")
public class TBaseEquipTypeController extends BaseController {

    private final ITBaseEquipTypeService iTBaseEquipTypeService;

    /**
     * 查询设备类型列表
     */
    @ApiOperation("查询设备类型列表")
    @PreAuthorize("@ss.hasPermi('modules:equipType:list')")
    @GetMapping("/list")
    public TableDataInfo<TBaseEquipTypeVo> list(TBaseEquipTypeQueryBo bo) {
        startPage();
        List<TBaseEquipTypeVo> list = iTBaseEquipTypeService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出设备类型列表
     */
    @ApiOperation("导出设备类型列表")
    @PreAuthorize("@ss.hasPermi('modules:equipType:export')")
    @Log(title = "设备类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TBaseEquipTypeVo> export(TBaseEquipTypeQueryBo bo) {
        List<TBaseEquipTypeVo> list = iTBaseEquipTypeService.queryList(bo);
        ExcelUtil<TBaseEquipTypeVo> util = new ExcelUtil<TBaseEquipTypeVo>(TBaseEquipTypeVo.class);
        return util.exportExcel(list, "设备类型");
    }

    /**
     * 获取设备类型详细信息
     */
    @ApiOperation("获取设备类型详细信息")
    @PreAuthorize("@ss.hasPermi('modules:equipType:query')")
    @GetMapping("/{equipTypeId}")
    public AjaxResult<TBaseEquipTypeVo> getInfo(@PathVariable("equipTypeId") Long equipTypeId) {
        return AjaxResult.success(iTBaseEquipTypeService.queryById(equipTypeId));
    }

    /**
     * 新增设备类型
     */
    @ApiOperation("新增设备类型")
    @PreAuthorize("@ss.hasPermi('modules:equipType:add')")
    @Log(title = "设备类型", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TBaseEquipTypeAddBo bo) {
        return toAjax(iTBaseEquipTypeService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改设备类型
     */
    @ApiOperation("修改设备类型")
    @PreAuthorize("@ss.hasPermi('modules:equipType:edit')")
    @Log(title = "设备类型", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TBaseEquipTypeEditBo bo) {
        return toAjax(iTBaseEquipTypeService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除设备类型
     */
    @ApiOperation("删除设备类型")
    @PreAuthorize("@ss.hasPermi('modules:equipType:remove')")
    @Log(title = "设备类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{equipTypeIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] equipTypeIds) {
        return toAjax(iTBaseEquipTypeService.deleteWithValidByIds(Arrays.asList(equipTypeIds), true) ? 1 : 0);
    }
}
